package com.example.dataextraction.service;

import com.example.dataextraction.dao.DataSourceMapper;
import com.example.dataextraction.datasources.MyDataSource;
import com.example.dataextraction.model.DataSource;
import com.example.dataextraction.utils.Encryp3DES;
import org.reflections.util.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author Zenan Chen
 * @date 2023/3/30 16:50
 */
@Service
public class DataSourceServiceImpl extends BaseServiceImpl implements DataSourceService {

    @Autowired
    private DataSourceMapper dataSourceMapper;

    @MyDataSource("second")
    @Override
    public void insert(DataSource dataSource) {
        fillBean(dataSource);
        if (!Utils.isEmpty(dataSource.getPassword())) {
            dataSource.setPassword(Encryp3DES.encryptDes(dataSource.getPassword()));
        }
        dataSourceMapper.insert(dataSource);
    }

    @MyDataSource("second")
    @Override
    public DataSource getByCode(String dataSourceCode) {
        return dataSourceMapper.selectByCode(dataSourceCode);
    }
}
